Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Graphics /
Chapter 2 - Geometric Shapes / Using Geometric Shapes


Creating and Drawing Curves

You can create and draw curve shapes with QuickDraw GX the same way you create and draw points and lines. Typically, you first define a curve geometry, which is encapsulated in a gxCurve structure:

struct gxCurve {
   struct gxPoint first;
   struct gxPoint control;
   struct gxPoint last;
};
The first and last fields determine the start point and the end point of the curve. The point specified in the control field lies off the curve and determines the tangents of the curve. (The off-curve control point could actually be on the curve--that is, directly between the first and last points--in which case the curve is a straight line.)

Once you've defined a curve geometry, you can create a curve shape using the GXNewCurve function and draw it using the GXDrawShape function, as shown in Listing 2-9.

Listing 2-9 Creating a curve shape

void CreateCurve(void)
{
   gxShape aCurveShape;
   
   static gxCurve aCurveGeometry = {ff(50), ff(50),   /* on */
                                    ff(100), ff(150), /* off */ 
                                    ff(200), ff(50)}; /* on */ 
                                 
   
   aCurveShape = GXNewCurve(&aCurveGeometry);
   
   GXDrawShape(aCurveShape);
   
   GXDisposeShape(aCurveShape);
}
Figure 2-22 shows the curve shape geometry, which includes the first and last points, the off-curve control point, and the tangents implied by these geometric points. This figure also shows the curve as drawn. It is drawn as a hairline (one-pixel wide) with the open-frame shape fill, which reflects the default values for curve shapes.

Figure 2-22 A curve

You could draw the same curve without creating a curve shape by calling the GXDrawCurve function:

GXDrawCurve(&aCurveGeometry);
You could also create the curve shape using the GXNewShape function described in Inside Macintosh: QuickDraw GX Objects or the GXNewShapeVector function described on page 2-109.

Curves have a direction that depends on the order of the points in the geometry. For example, you could reverse the direction of the curve in Figure 2-22 by reversing the order of the points in the geometry definition from Listing 2-9:

static gxCurve aCurveGeometry = {ff(200), ff(50),  /* on curve */
                                 ff(100), ff(150), /* off curve */
                                 ff(50), ff(50)};  /* on curve */
Changing the direction of this curve would not change its appearance. However, curve direction can affect the appearance of a curve when you apply certain stylistic variations, such as dashing, to the curve. The next chapter, "Geometric Styles," discusses these stylistic variations. Also, when a curve is part of a path shape, the direction of the curve can affect the way the path is drawn. See "Creating and Drawing Paths" beginning on page 2-55 for examples of how the direction of a curve can affect drawing.

For more information about curve shapes, see "Curve Shapes" on page 2-18 and "The Curve Structure" on page 2-105. For information about the functions you can use to create and draw curves, see the description of the GXNewCurve function on page 2-113 and the GXDrawCurve function on page 2-159.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help